from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from game_core.models import Monster, Skill
from .models import Achievement

@login_required
def collection_home(request):
    """图鉴主页视图"""
    context = {
        'monster_count': Monster.objects.count(),
        'skill_count': Skill.objects.count(),
        'achievement_count': Achievement.objects.count()
    }
    return render(request, 'collection/index.html', context)

@login_required 
def monster_collection(request):
    """怪物图鉴列表视图"""
    monsters = Monster.objects.all()
    return render(request, 'collection/monster_list.html', {'monsters': monsters})

@login_required
def monster_detail(request, monster_id):
    """怪物详情视图"""
    monster = get_object_or_404(Monster, id=monster_id)
    return render(request, 'collection/monster_detail.html', {'monster': monster})

@login_required
def skill_collection(request):
    """技能图鉴列表视图"""
    skills = Skill.objects.all()
    return render(request, 'collection/skill_list.html', {'skills': skills})

@login_required
def skill_detail(request, skill_id):
    """技能详情视图"""
    skill = get_object_or_404(Skill, id=skill_id)
    return render(request, 'collection/skill_detail.html', {'skill': skill})

@login_required
def achievement_list(request):
    """成就列表视图"""
    achievements = Achievement.objects.all()
    return render(request, 'collection/achievement_list.html', {'achievements': achievements})

@login_required
def achievement_detail(request, achievement_id):
    """成就详情视图"""
    achievement = get_object_or_404(Achievement, id=achievement_id)
    return render(request, 'collection/achievement_detail.html', {'achievement': achievement})